import { getPermission } from '@/api/user'
import { asyncRoutes, constantRoutes } from '@/router'

const state = {
  routes: []

}
const mutations = {
  getRoutes(state, menus) {
    state.routes = [...constantRoutes, ...menus]
  },
  removeRoute(state) {
    state.routes = []
  }
}

const actions = {
  async  getPerm(store) {
    const { menus } = await getPermission()
    const routes = asyncRoutes.filter(route => {
      return menus.includes(route.name)
    })
    store.commit('getRoutes', routes)
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

